<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>


<chiptrack:checkLogon sourcePage="/salesQuotations.do?isSample=1"/>

<%@ page import="java.util.ArrayList,
                 com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User,
                 com.scalar.chiptrack.sales.Orders"%>
<%@ page import="com.scalar.chiptrack.commons.Constants" %>
<%@ page import="com.scalar.chiptrack.utils.StringUtils" %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>
<META content="MSHTML 5.50.4807.2300" name=GENERATOR>

<SCRIPT language="JavaScript">
    var dateElement = "";
    function openCalendar(dateValue)
    {
        dateElement = dateValue;
        newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
        newWindow.moveTo(550,180);
        newWindow.focus();
    }
	function assignDate(passedValue)
    {
	    dateElement.value=passedValue;
	    window.focus();
    }

    function validateFromAndToDates()
    {
        formdoc = document.quoteSearchForm;
        errMsg = '';

        var pa	= document.getElementById("errors")

        if( chkDate( formdoc.fromDate.value, 'From-Date', 'N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.fromDate.focus();
            return false;
        }
        if( chkDate( formdoc.toDate.value, 'To-Date', 'N') == false)
        {
            pa.innerHTML = errMsg;
            formdoc.toDate.focus();
            return false;
        }
        if( formdoc.fromDate.value!='' && formdoc.toDate.value!='')
        {
            if ( !validateDateOut( formatDateAsMMDDYYYY( formdoc.fromDate.value), formatDateAsMMDDYYYY( formdoc.toDate.value ) ) )
            {
                pa.innerHTML = "To Date cannot be less than From Date";
                formdoc.toDate.focus();
                return false;
            }
        }
        return true;
    }

    function searchOrderList(theForm)
    {
        var success;
        success = true;
		success = validateFromAndToDates();
		if(success == false)
        {
           return false;
        }
        theForm.action.value = "SearchQuotation";
        //theForm.submit();
        return true;
    }

    function GetAllProducts()
    {
        newWindow = window.open('loadProducts.do','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=500,height=600,left=300,top=30,resizable=no');
  	    newWindow.focus();
    }

    function assignProduct(passedValue)
    {
	    document.quoteSearchForm.manufacturingPartNo.value = passedValue;
	    window.focus();
    }

    function showErrorReportPage()
    {
        newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
        newWindow.focus();
    }

</SCRIPT>


<SCRIPT language='JavaScript'>

    function openSalesOrder()
    {
        var isSample = document.quoteSearchForm.isSample.value;
        window.open('order.do?action=printOrder&revisedDate=false&salesOrderId=<%=(String)request.getAttribute("salesOrderId")%>&isSample='+isSample,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=600,height=600,left=100,top=50,resizable=yes');
    }

    function openQuotation()
    {
        newWindow = window.open('quotationView.do?action=printQuotation&quotationId=<%=(String)request.getAttribute("quotationId")%>&quotationNo=<%=request.getParameter("quotationNo")%>','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=600,height=600,left=100,top=50,resizable=yes');
  	    newWindow.focus();
    }
    function openQuotationtoView( quoteId, quoteNo )
    {
       newWindow = window.open('quotationView.do?action=printQuotation&quotationId='+quoteId+'&quotationNo='+quoteNo,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=800,height=600,left=100,top=50,resizable=yes');
  	   newWindow.focus();
    }


</SCRIPT>
</HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
    <%
        String userTypeChiptrac = Constants.USER_TYPE_CHIPTRAC + "";
    %>
    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/header.jsp" %>
    </logic:equal>
    <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/extHeader.jsp" %>
    </logic:notEqual>

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
<%
    String heading = "";
    String isSample = "1";

    if((request.getParameter("isSample") != null) && (request.getParameter("isSample").equals("0")))
    {
         heading = "Sample Order";
    %>
	    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
           <%@ include file="/jsp/sales/sample_order_menu.jsp" %>
        </logic:equal>
        <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/ext_sample_order_menu.jsp" %>
        </logic:notEqual>
    <%
    }
    else if((request.getParameter("quotation") != null) && (request.getParameter("quotation").equals("0")))
    {
        heading = "Quote";
    %>
        <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
           <%@ include file="/jsp/sales/sales_order_menu.jsp" %>
        </logic:equal>
        <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/ext_sales_order_menu.jsp" %>
        </logic:notEqual>
    <%
    }
    else
    {
        heading = "Sales Order";
    %>
        <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
           <%@ include file="/jsp/sales/sales_order_menu.jsp" %>
        </logic:equal>
        <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <%@ include file="/jsp/sales/ext_sales_order_menu.jsp" %>
        </logic:notEqual>
    <%
    }
%>

<!-- end of the side navigations -->

</TD>

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>

<!-- from here your body starts -->


<html:form name="quoteSearchForm" onsubmit="javascript:return searchOrderList(document.quoteSearchForm);" method="post" action="/salesQuotations" type="com.scalar.chiptrack.sales.forms.QuoteSearchForm">

<center><span class="NArialW">Search for <%=heading%> to modify </span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10>

<div align=right>
<table border="0" width="90%">
 <tr><td>
    <chiptrack:info styleClass="NArialL" />
    <chiptrack:errors styleClass="NArialL" />
    <chiptrack:messages type="info" styleClass="NArialL" />
     <b><font face="Verdana" size="-5" align="center" color="#ff0000" id="errors"></font></b>
 </td></tr>
</table>
</div>

<table border="0" width="100%" align=center>
 <tr><td>
 <table border="0" width="90%" align=center>
    <tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
    <tr>
        <td width="25%" class="NArialL">
	        Product Name<br>(<bean:message key="label.mfgPartNumber" />)
	    </td>
        <td width="15%" class="NArialL">
            <html:select name="quoteSearchForm" property="manufacturingPartNo" styleClass="txfield">
                <html:options collection="productList" property="value" labelProperty="label"/>
            </html:select>
        </td>
        <td width="15%" align="left" class="NArialL">Customer</td>
        <td width="20%" class="NArialL">
            <html:select name="quoteSearchForm" property="customerId" styleClass="txfield">
                <html:options collection="customerList" property="value" labelProperty="label"/>
            </html:select>
        </td>
    </tr>
    <tr>
        <td width="15%" class="NArialL">Quote #</td>
        <td width="20%" class="NArialL">
            <html:text name="quoteSearchForm" property="quotationId" size="20" styleClass="txfield" />
        </td>
        <td width="10%" align="left" class="NArialL"><bean:message key="label.sales.endCustomer"/></td>
        <td width="10%" class="NArialL">
            <html:select name="quoteSearchForm" property="endUser" styleClass="txfield">
                <html:options collection="endUserList" property="value" labelProperty="label"/>
            </html:select>
        </td>
    </tr>
    <tr>
        <td width="25%" class="NArialL">Customer PO#</td>
        <td width="15%" class="NArialL">
            <html:text name="quoteSearchForm" property="customerPO" size="20" styleClass="txfield" />
        </td>
        <td width="15%" align="right" class="NArialL">
            <logic:equal name="viewExpired" value="YES">
                <input type="checkbox" name="viewExpired" CHECKED >
            </logic:equal>
            <logic:equal name="viewExpired" value="NO">
                <input type="checkbox" name="viewExpired" >
            </logic:equal>
        </td>
        <td width="20%" class="NArialL">Include expired quotes.</td>
    </tr>
     <tr>
        <td width="25%" class="NArialL">From Date</td>
        <td width="15%" class="NArialL">
            <html:text name="quoteSearchForm" property="fromDate" size="12" styleClass="txfield" />
            <a href="javascript:openCalendar(document.quoteSearchForm.fromDate)"onmouseover="window.status='Click to Select From Date';return true"onmouseout="window.status='';return true"title="Click here to Select From Date">
                <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18>
            </a>
        </td>
        <td width="15%" align="left" class="NArialL">To Date</td>
        <td width="20%" class="NArialL">
            <html:text name="quoteSearchForm" property="toDate" size="12" styleClass="txfield" />
            <a href="javascript:openCalendar(document.quoteSearchForm.toDate)"onmouseover="window.status='Click to Select To Date';return true"onmouseout="window.status='';return true"title="Click here to Select To Date">
                <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18>
            </a>
        </td>
    </tr>
    <tr><td colsapn=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
	<tr><td colspan=5></td></tr>
 <tr>
      <td colspan=5 align=center>
       <%--  <a href="javascript:searchOrderList(document.quoteSearchForm);" onmouseover="window.status='Click to Search for Quote';return true" title="Click here to Search for Quote" onmouseout="window.status='';return true"><input type=image border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17"></a> --%>
         <%--Modified by varma 2 aug 2004 --%>
         <input type=image border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17" onmouseover="window.status='Click to Search for Quote';return true" title="Click here to Search for Quote" onmouseout="window.status='';return true" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <a href="javascript:document.quoteSearchForm.reset();" onmouseover="window.status='Click to reset the values';return true" title="Click here to Reset" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a></td>
    </tr>
   </table>
   </td></tr>
   <tr><td><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
   <tr><td>
   <logic:equal name="showList" value="TRUE">
   <table border="0" width="100%" bordercolor="#FFFFFF" align=right>
	<tr>
	  <td width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Quote #</font></td>
	  <td width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Quote Type</font></td>
	  <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Customer Name</font></td>
	  <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Part Number</font></td>
	  <td width="20%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.sales.shipToCustomer"/></font></td>
	  <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.sales.endUser"/></font></td>
	  <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Qty</font></td>
	  <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.sales.price"/></font></td>
	  <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.sales.suggestedResalePrice"/></font></td>
	  <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Created On</font></td>
	  <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Expiry Date</font></td>
	  <td width="30%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Actions</font></td>
	</tr>
        <% int bgcount = 0;%>
        <tr><td colspan=5></td></tr>

        <% ArrayList orderList = ( ArrayList ) request.getAttribute( "ordersList" ); %>
	<logic:iterate id="Orders" name="ordersList" type="com.scalar.chiptrack.sales.Orders">
        <% bgcount = bgcount + 1; %>
    <%--<logic:equal name="Orders" property="isCancel" value="false">--%>
    <tr bgcolor='<%=(bgcount%2==0) ? "#DEE1E2" : "#FFFFEE"%>'>
	  <td width="10%" align="center" nowrap class="NArialL" ><bean:write name="Orders" property="salesOrderNo"  /></td>
	  <td width="10%" align="left" class="NArialL"><bean:write name="Orders" property="quoteType" /></td>
	  <td width="15%" align="left" class="NArialL"><bean:write name="Orders" property="customerName" /></td>
	  <td width="15%" align="left" class="NArialL"><bean:write name="Orders" property="productName" /></td>
	  <td width="15%" align="left" class="NArialL"><bean:write name="Orders" property="endCustomerName" /></td>
	  <td width="15%" align="left" class="NArialL"><bean:write name="Orders" property="endUserName" /></td>
	  <td width="15%" align="right" class="NArialL"><%=StringUtils.formatUnits( Orders.getQty() )%></td>
	  <td width="15%" align="right" class="NArialL"><%=StringUtils.formatAmountWithNoOfDecimals( Orders.getUnitPrice() )%></td>
	  <td width="15%" align="right" class="NArialL"><%=StringUtils.formatAmountWithNoOfDecimals( Orders.getSuggResalePrice() )%></td>
	  <td width="15%" align="center" class="NArialL"><bean:write name="Orders" property="bookingDate" /></td>
      <td width="15%" align="center" class="NArialL"><bean:write name="Orders" property="expiryDate" /></td>


	  <td width="30%" align="center">

        <table width='100%' border="0">
        <tr>

        <td align="center" width="25%">
        <font class="leftsection">
        <%
            Orders orders = ( Orders ) orderList.get( bgcount -1 );
            int quotationId = orders.getSalesOrderId();
            String quotationNo = orders.getSalesOrderNo();
        %>
        <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <logic:equal name="Orders" property="isTotallyApproved" value="true">
                &nbsp;
            </logic:equal>
            <logic:equal name="Orders" property="isTotallyApproved" value="false">
                <chiptrack:restrictedLink functionality='<%=Functionality.CHANGE_QUOTATION%>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href='<%=chipTracContext + "/changeQuotation.do?quotationId=" + quotationId + "&quotation=0&isSample=" + isSample%>' onmouseover="window.status='Click to Modify Quotation';return true" onmouseout="window.status='';return true">Modify</chiptrack:restrictedLink>
            </logic:equal>
        </logic:notEqual>
        <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
            <chiptrack:restrictedLink functionality='<%=Functionality.CHANGE_QUOTATION%>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href='<%=chipTracContext + "/changeQuotation.do?quotationId=" + quotationId + "&quotation=0&isSample=" + isSample%>' onmouseover="window.status='Click to Modify Quotation';return true" onmouseout="window.status='';return true">Modify</chiptrack:restrictedLink>
        </logic:equal>
        </font>

        </td>
    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <td align="center" width="29%">
        <font class="leftsection">
        <logic:equal name="Orders" property="isExpire" value="false">
            <logic:equal name="Orders" property="isTotallyApproved" value="true">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </logic:equal>
          <logic:equal name="Orders" property="isApproved" value="false">
            <logic:equal name="Orders" property="isTotallyApproved" value="false">
                <chiptrack:restrictedLink functionality='<%=Functionality.APPROVE_QUOTATION%>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href='<%=chipTracContext + "/approveQuotation.do?quotationId=" + quotationId + "&quotation=0&isSample=" + isSample%>' onmouseover="window.status='Click to Approve Quotation';return true" onmouseout="window.status='';return true">Approve</chiptrack:restrictedLink>
            </logic:equal>
          </logic:equal>
        </logic:equal>

        <logic:notEqual name="Orders" property="isExpire" value="false">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
        </logic:notEqual>
        </font>
        </td>
    </logic:equal>


        <td align="center" width="29%">
        <font class="leftsection">
        <logic:equal name="Orders" property="isExpire" value="false">
            <logic:equal name="Orders" property="isApproved" value="true">
                <logic:equal name="Orders" property="isTotallyTransferred" value="false">
                    <chiptrack:restrictedLink functionality='<%=Functionality.CHANGE_QUOTATION%>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href='<%=chipTracContext + "/transferQuotation.do?quotationId=" + quotationId + "&quotation=0&isSample=" + isSample%>' onmouseover="window.status='Click to Transfer Quotation';return true" onmouseout="window.status='';return true">Transfer</chiptrack:restrictedLink>
                </logic:equal>
            </logic:equal>
            <logic:notEqual name="Orders" property="isApproved" value="true">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </logic:notEqual>
        </logic:equal>

        <logic:notEqual name="Orders" property="isExpire" value="false">
        &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </logic:notEqual>
        </font>
        </td>

        <td align="center" width="17%">
        <font class="leftsection">
            <chiptrack:restrictedLink functionality='<%=Functionality.CHANGE_QUOTATION%>' action='<%=User.USER_ACTION_VIEW%>' styleClass="leftsection" href='<%="javascript:openQuotationtoView(" + quotationId + ",\'" + quotationNo + "\');" %>' onmouseover="window.status='Click to View Quotation';return true" onmouseout="window.status='';return true"> View </chiptrack:restrictedLink>
        </font>
        </td>

        </tr>
        </table>

      </td>
	</tr>
      <%--  </logic:equal>--%>
        </logic:iterate>
    </table>
    </logic:equal>

    </td></tr>

</table>

<input type="hidden" name="action" value="">
<input type="hidden" name="isSample" value="<%=request.getParameter("isSample")%>">
</html:form>


<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>
<!-- Footer starts here -->

<%@ include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->

</BODY>
</HTML>
